<?php

namespace App\Http\Resources\Train\TrainOrder;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

class TrainOrderRefundResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     *
     * @return array|Arrayable|JsonSerializable
     */
    public function toArray($request)
    {
        $refund_info = parent::toArray($request);
        if (isset($refund_info['title'])) {
            $refund_info['title'] = __($refund_info['title']);
        }
        if (isset($refund_info['refund_amount_details'])) {
            $refund_info['refund_amount_details'] = TrainOrderRefundDetailResource::collection($refund_info['refund_amount_details']);
        }
        if (isset($refund_info['details'])) {
            $refund_info['refund_amount_details'] = TrainOrderRefundDetailResource::collection($refund_info['details']);
        }
        unset($refund_info['details'], $refund_info['user_id']);
        return $refund_info;
    }
}
